import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as express from 'express'
// main.ts
import * as fs from 'fs';
import * as path from 'path';
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const uploadDir = path.join(__dirname, 'uploads');
  if (!fs.existsSync(uploadDir)) {
    fs.mkdirSync(uploadDir, { recursive: true });
  }
  // 全局启用CORS
  app.enableCors({
    origin: '*', // 允许所有来源，或者指定具体的域名如 'http://localhost:3000'
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
    allowedHeaders: 'Content-Type,Authorization', // 根据需要调整
    credentials: true, // 如果需要支持凭证（cookies, HTTP authentication），则设为true
  });

  // 设置上传文件可访问路径
  app.use('/uploads', express.static('uploads')); // 确保已导入express
  
  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();